//
//  HLGudieCell.m
//  weibo-OC
//
//  Created by 黄力 on 15/12/17.
//  Copyright © 2015年 HLTest. All rights reserved.
//

#import "HLGudieCell.h"
#import <Masonry.h>

@interface HLGudieCell ()

@property (nonatomic,strong) UIImageView *backImageView;
@property (nonatomic,strong) UIButton *startBtn;

@end

@implementation HLGudieCell


//重写构造方法
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //设置界面
        [self setupUI];
    }
    return self;
}

//设置置界面
- (void)setupUI {
    //添加子控件
    [self.contentView addSubview:self.backImageView];
    [self.contentView addSubview:self.startBtn];
    //设置自动布局
    //背景图片
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.edges.equalTo(self);
    }];
    //开始按钮
    [self.startBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.backImageView.mas_centerX);
        make.top.equalTo(self.backImageView.mas_bottom).with.offset(-200);
    }];
    //添加按钮的点击响应事件
    [self.startBtn addTarget:self action:@selector(clickStartBtn) forControlEvents:UIControlEventTouchUpInside];
    
}

//重写set方法
- (void)setIndex:(NSInteger)index {
    _index = index;
    //根据索引来修改图片
    self.backImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"new_feature_%ld",index + 1]];
//    //隐藏按钮
    self.startBtn.hidden = YES;
    
}

//开始按钮的动画
- (void)startBtnAnimation {
    //设置按钮比例为0
    self.startBtn.transform = CGAffineTransformMakeScale(0, 0);
    
    //显示按钮
    self.startBtn.hidden = NO;
    
    //动画
    [UIView animateWithDuration:1.5 delay:0 usingSpringWithDamping:0.9 initialSpringVelocity:8 options:0 animations:^{
        //让按钮恢复原来大小
        self.startBtn.transform = CGAffineTransformIdentity;
    } completion:nil];
    
}

//按钮的点击事件
- (void)clickStartBtn {
    //发送通知
    [[NSNotificationCenter defaultCenter] postNotificationName:MainWindowChangeRootControllerNotification object:nil];
}

#pragma mark - 懒加载子控件
//背景图片
- (UIImageView *)backImageView {
    if (_backImageView == nil) {
        _backImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"new_feature_1"]];
    }
    return _backImageView;
}
//开始按钮
- (UIButton *)startBtn {
    if (_startBtn == nil) {
        _startBtn = [[UIButton alloc] initWithTitle:@"开始体验" withTitleFont:16 withBackImageName:@"new_feature_finish_button"];
    }
    return _startBtn;
}

@end
